y= input ()
 
if len(str(y)) != 4:
    print(0)
else:
    xc = False
    for length in range(4, 0, -1):
        if xc:
            break
        for i in range(4 - length + 1):
            vg = int(str(y)[i:i+length])
            if vg < 2:
                continue
            for j in range(2, int(vg**0.5) + 1):
                if vg % j == 0:
                    break
            else:
                print(vg)
                xc = True
                break
    if not xc:
        print(0)
